1. Field of the Invention
The present invention relates to an information processing apparatus and a context switching method.
2. Description of the Related Art
In recent years, computer systems that are embedded iii various machines and apparatuses and perform control tc) realize specific functions, so-called embedded systems, have been drawing attention, and their application to personal computer peripherals, audio-video equipment, electric appliances, and the like has been spreading rapidly. Moreover, so-called real-time capability to respond and process in a given time period after accepting a request to process is required of software (embedded software) for use in embedded systems. Hence, for embedded systems, a real-time operating system (hereinafter, called a “real-time OS”) is often adopted.
As mentioned above, the real-time OS must ensure a response in a given time period, and hence adopt a multithread function or a multitask function as indispensable technology. The multithread function is a function wherein in a processor such as a CPU or MPU, one application process is divided into threads that are units of processing thereof and the execution rights of the threads are switched thereby processing the threads in parallel. The multitask function is a function wherein in a processor, each thread is further divided into a plurality of tasks that are units of processing and the execution rights of the plurality of tasks are switched thereby processing the tasks in parallel.
When a plurality of units of processing (threads, tasks processes, or the like) are switched, “contexts” for use in the units of processing are usually switched. Note that the context is associated with a respective unit of processing and includes current flag status of a register set (general purpose registers, status registers, a program counter, and the like) and information for execution of the unit of processing. The definition of the context is according to that described in Michael Barr, “Programming Embedded Systems with C and C++”, Ohm-sha, Ltd., April 2000, pp. 180-181 (or O'Reilly, January 1999).
FIG. 9 is a diagram for explaining the operation of context switching in a conventional embedded system (hereinafter, called “conventional example 1”). As shown in the Figure, the conventional embedded system essentially comprises a CPU 10, a register bank 11 that stores a context, and a memory 12 external to the CPU 10 for saving/restoring contexts. After accepting a request to switch contexts from the real-time OS (step 0), the CPU 10 saves a context A now being executed from the register bank 11 into the memory 12 by a store instruction (step 1). Then, the CPU 10 restores a next context B from the memory 12 and updates the contents of the register bank 11 therewith by a load instruction (step 2). Such a conventional example 1 is disclosed in, for example, Japanese Patent Application Laid-Open Publication No. H09-212371.
FIG. 10 is a diagram for explaining the operation of context switching in another conventional embedded system (hereinafter, called “conventional example 2”). As shown in the Figure, the conventional embedded system essentially comprises a CPU 10, a plurality of register banks 11 that are associated with and exclusively used by respective tasks, a selector 13 that selects one of respective contexts stored in the plurality of register banks 11. Here, assume that the CPU 10 is executing a task A with a context A stored in a register bank 11 (#0) via the selector 13 (step 0). After accepting a request to switch contexts from the real-time OS, the CPU 10 selects a register bank 11(#1) storing a context B with the selector 13 (step 1). As a result, context switching from context A to context B is carried out (step 2). That is, in conventional example 2, without saving/restoring a context into/from an external memory, context switching is carried out only by switching the register banks 11. Such conventional example 2 is disclosed in, for example, Japanese Patent Application Laid-Open Publication No. H07-141208.
FIG. 11 shows how contexts A to C associated with respective tasks A to C are also switched as the tasks A to C are switched according to a given task scheduling (of A to B to C to A to . . . ) in conventional example 1 of FIG. 9. In conventional example 1, when switching contexts, the CPU 10 saves the status of the context currently granted an execution right into the memory 12 by a store instruction, and restores the status of a context to be granted an execution right from the memory 12 by a load instruction.
That is, in conventional example 1, the CPU 10 saves/restores contexts by repeating execution of a store instruction/load-instruction. As a result, context switching takes some time (overhead), and accordingly responsiveness in task switching and execution, so-called real-time capability is poorer. Furthermore, the CPU 10 cannot execute another application during the saving/restoring, thus affecting adversely the real-time capability.
Meanwhile, in conventional example 2 of FIG. 10 saving/restoring of contexts into/from an external memory is not performed, and accordingly high-speed context switching can be achieved. However, a hardware resource usually provided as register banks is limited, and thus this configuration is hardly realistic for other than embedded systems on a relatively small scale with a small number of contexts to be handled.